﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Business.DAL
{
    public class t_Intention_BillPrintInfo
    {
        public t_Intention_BillPrintInfo()
        { }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_Intention_BillPrintInfo(");
            strSql.Append("RecordId,IntentionId,IntentionCode,PrintTime,PrintEmployeeId,PrintEmployee,BillType)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@IntentionId,@IntentionCode,@PrintTime,@PrintEmployeeId,@PrintEmployee,@BillType)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "IntentionId", DbType.Guid, model.IntentionId);
            db.AddInParameter(dbCommand, "IntentionCode", DbType.AnsiString, model.IntentionCode);
            db.AddInParameter(dbCommand, "PrintTime", DbType.DateTime, model.PrintTime);
            db.AddInParameter(dbCommand, "PrintEmployeeId", DbType.Guid, model.PrintEmployeeId);
            db.AddInParameter(dbCommand, "PrintEmployee", DbType.AnsiString, model.PrintEmployee);
            db.AddInParameter(dbCommand, "BillType", DbType.Int32, model.BillType);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,IntentionId,IntentionCode,PrintTime,PrintEmployeeId,PrintEmployee,BillType from t_Intention_BillPrintInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,IntentionId,IntentionCode,PrintTime,PrintEmployeeId,PrintEmployee,BillType ");
            strSql.Append(" FROM t_Intention_BillPrintInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,IntentionId,IntentionCode,PrintTime,PrintEmployeeId,PrintEmployee,BillType ");
            strSql.Append(" FROM t_Intention_BillPrintInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo> list = new List<Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo model = new Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["IntentionId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IntentionId = new Guid(ojb.ToString());
            }
            model.IntentionCode = dataReader["IntentionCode"].ToString();
            ojb = dataReader["PrintTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PrintTime = (DateTime)ojb;
            }
            ojb = dataReader["PrintEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PrintEmployeeId = new Guid(ojb.ToString());
            }
            model.PrintEmployee = dataReader["PrintEmployee"].ToString();
            ojb = dataReader["BillType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BillType = (int)ojb;
            }
            return model;
        }
    }
}
